home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / sftgrd / 2_groups.frm < prev    next >
Text File  |  1996-06-12  |  7KB  |  292 lines

  1. VERSION 2.00
  2. Begin Form fmtTwoGroups 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Two Groups"
  5.    ClientHeight    =   5820
  6.    ClientLeft      =   1095
  7.    ClientTop       =   1485
  8.    ClientWidth     =   7365
  9.    Height          =   6225
  10.    Left            =   1035
  11.    LinkTopic       =   "Form7"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   5820
  15.    ScaleWidth      =   7365
  16.    Top             =   1140
  17.    Width           =   7485
  18.    Begin CommandButton cmdCancel 
  19.       Cancel          =   -1  'True
  20.       Caption         =   "Cancel"
  21.       Default         =   -1  'True
  22.       Height          =   495
  23.       Left            =   3120
  24.       TabIndex        =   7
  25.       Top             =   4800
  26.       Width           =   1215
  27.    End
  28.    Begin CommandButton cmdOK 
  29.       Caption         =   "OK"
  30.       Height          =   495
  31.       Left            =   3120
  32.       TabIndex        =   6
  33.       Top             =   4080
  34.       Width           =   1215
  35.    End
  36.    Begin CommandButton cmdRemoveAll 
  37.       Caption         =   "Remove All"
  38.       Height          =   495
  39.       Left            =   3120
  40.       TabIndex        =   4
  41.       Top             =   2760
  42.       Width           =   1215
  43.    End
  44.    Begin CommandButton cmdRemove 
  45.       Caption         =   "<== Remove"
  46.       Height          =   495
  47.       Left            =   3120
  48.       TabIndex        =   3
  49.       Top             =   1800
  50.       Width           =   1215
  51.    End
  52.    Begin CommandButton cmdAdd 
  53.       Caption         =   "Add  ==>"
  54.       Height          =   495
  55.       Left            =   3120
  56.       TabIndex        =   2
  57.       Top             =   840
  58.       Width           =   1215
  59.    End
  60.    Begin ListBox lstRight 
  61.       Height          =   4905
  62.       Left            =   4800
  63.       MultiSelect     =   2  'Extended
  64.       TabIndex        =   1
  65.       Top             =   600
  66.       Width           =   2295
  67.    End
  68.    Begin ListBox lstLeft 
  69.       Height          =   4905
  70.       Left            =   360
  71.       MultiSelect     =   2  'Extended
  72.       Sorted          =   -1  'True
  73.       TabIndex        =   0
  74.       Top             =   600
  75.       Width           =   2295
  76.    End
  77.    Begin Label lblRight 
  78.       Alignment       =   2  'Center
  79.       BackColor       =   &H00C0C0C0&
  80.       BorderStyle     =   1  'Fixed Single
  81.       Caption         =   "lblRight"
  82.       FontBold        =   -1  'True
  83.       FontItalic      =   0   'False
  84.       FontName        =   "MS Sans Serif"
  85.       FontSize        =   8.25
  86.       FontStrikethru  =   0   'False
  87.       FontUnderline   =   -1  'True
  88.       Height          =   375
  89.       Left            =   4800
  90.       TabIndex        =   9
  91.       Top             =   240
  92.       Width           =   2295
  93.    End
  94.    Begin Label lblLeft 
  95.       Alignment       =   2  'Center
  96.       BackColor       =   &H00C0C0C0&
  97.       BorderStyle     =   1  'Fixed Single
  98.       Caption         =   "lblLeft"
  99.       FontBold        =   -1  'True
  100.       FontItalic      =   0   'False
  101.       FontName        =   "MS Sans Serif"
  102.       FontSize        =   8.25
  103.       FontStrikethru  =   0   'False
  104.       FontUnderline   =   -1  'True
  105.       Height          =   375
  106.       Left            =   360
  107.       TabIndex        =   8
  108.       Top             =   240
  109.       Width           =   2295
  110.    End
  111.    Begin Label lblExitStatus 
  112.       Caption         =   "ExitStatus"
  113.       Height          =   495
  114.       Left            =   3120
  115.       TabIndex        =   5
  116.       Top             =   5280
  117.       Visible         =   0   'False
  118.       Width           =   1215
  119.    End
  120. End
  121. ': 2_GROUPS.FRM
  122. '-    Manage what is in two groups
  123. '
  124. ' Copyright 1994, AA-Software International
  125. '     Distributed for non-commercial educational use only.
  126. '     For other use contact:
  127. '        AA-Software International
  128. '        12 ter Domaine Du Bois Joli
  129. '        06330 Roquefort-Les-Pins, France
  130. '
  131. '        Tel: (+33) 93.77.50.47
  132. '        Fax: (+33) 93.77.19.78
  133. '        Internet: cswilly@acm.org
  134. '        CompuServe: 100343,2570
  135. '
  136. Option Explicit
  137.  
  138. Sub cmdAdd_Click ()
  139.    pAddToRight
  140.  
  141. End Sub
  142.  
  143. Sub cmdCancel_Click ()
  144.    lblExitStatus.Caption = "CANCEL"
  145.    Me.Hide
  146. End Sub
  147.  
  148. Sub cmdOK_Click ()
  149.    lblExitStatus.Caption = "OK"
  150.    Me.Hide
  151. End Sub
  152.  
  153. Sub cmdRemove_Click ()
  154.  
  155.    pAddToLeft
  156.  
  157. End Sub
  158.  
  159. Sub cmdRemoveAll_Click ()
  160.    Dim itemKtr_i As Integer
  161.  
  162.    'Move all items from Right group to Left group
  163.    For itemKtr_i = 0 To lstRight.ListCount - 1
  164.       lstLeft.AddItem lstRight.List(itemKtr_i)
  165.    Next itemKtr_i
  166.  
  167.    'Remove All Groups from In-favor list
  168.    lstRight.Clear
  169.  
  170.    pSetRemoveAllButton
  171.    pSetFocus lstRight, lstLeft
  172.  
  173. End Sub
  174.  
  175. Sub Form_Activate ()
  176.    pSetRemoveAllButton
  177.    pSetFocus lstLeft, lstRight
  178. End Sub
  179.  
  180. Sub Form_Load ()
  181.    cmdAdd.Enabled = False
  182.    cmdRemove.Enabled = False
  183. End Sub
  184.  
  185. Sub lstLeft_Click ()
  186.    cmdAdd.Enabled = True
  187.    cmdRemove.Enabled = False
  188. End Sub
  189.  
  190. Sub lstLeft_DblClick ()
  191.    pAddToRight
  192. End Sub
  193.  
  194. Sub lstRight_Click ()
  195.    cmdAdd.Enabled = False
  196.    cmdRemove.Enabled = True
  197. End Sub
  198.  
  199. Sub lstRight_DblClick ()
  200.    pAddToLeft
  201. End Sub
  202.  
  203. Private Sub pAddToLeft ()
  204.  
  205.    pMoveItem lstRight, lstLeft
  206.  
  207. End Sub
  208.  
  209. Private Sub pAddToRight ()
  210.    
  211.    pMoveItem lstLeft, lstRight
  212.    
  213. End Sub
  214.  
  215. Private Sub pMoveItem (lstFrom As Control, lstTo As Control)
  216.  
  217.    Dim insertPoint_i As Integer
  218.    insertPoint_i = lstTo.ListIndex + 1
  219.    If insertPoint_i > lstTo.ListCount Then insertPoint_i = lstTo.ListCount
  220.    
  221.    Dim itemKtr_i As Integer
  222.  
  223.    'Copy from lstFrom to lstTo
  224.    For itemKtr_i = 0 To lstFrom.ListCount - 1
  225.       If lstFrom.Selected(itemKtr_i) Then
  226.          lstTo.AddItem lstFrom.List(itemKtr_i), insertPoint_i
  227.          insertPoint_i = insertPoint_i + 1
  228.       End If
  229.    Next itemKtr_i
  230.  
  231.    'Remove from lstFrom
  232.    itemKtr_i = 0
  233.    Do While itemKtr_i < lstFrom.ListCount
  234.  
  235.       If lstFrom.Selected(itemKtr_i) Then
  236.          lstFrom.RemoveItem (itemKtr_i)
  237.       Else
  238.          itemKtr_i = itemKtr_i + 1
  239.       End If
  240.       
  241.    Loop
  242.  
  243.    lstTo.Selected(lstTo.ListIndex) = False
  244.    lstTo.ListIndex = insertPoint_i - 1
  245.    lstTo.Selected(lstTo.ListIndex) = True
  246.  
  247.    pSetRemoveAllButton
  248.    pSetFocus lstFrom, lstTo
  249.  
  250.  
  251. End Sub
  252.  
  253. Private Sub pSetFocus (c1 As Control, c2 As Control)
  254.  
  255.    If c1.ListCount = 0 Then
  256.       'clear select flag
  257.       Dim listKtr_i As Integer
  258.       For listKtr_i = 0 To c2.ListCount - 1
  259.          c2.Selected(listKtr_i) = False
  260.       Next listKtr_i
  261.  
  262.       'Select first item
  263.       c2.ListIndex = 0
  264.       c2.Selected(c2.ListIndex) = True
  265.  
  266.       c2.SetFocus
  267.       Exit Sub
  268.    End If
  269.  
  270.    If c1.ListIndex >= 0 Then
  271.       'Select the current items
  272.       c1.Selected(c1.ListIndex) = True
  273.    Else
  274.       'Must have fallen off the end of the list Select the last items
  275.       c1.ListIndex = c1.ListCount - 1
  276.       c1.Selected(c1.ListIndex) = True
  277.    End If
  278.  
  279.    c1.SetFocus
  280.  
  281. End Sub
  282.  
  283. Private Sub pSetRemoveAllButton ()
  284.    
  285.    If lstRight.ListCount > 1 Then
  286.       cmdRemoveAll.Enabled = True
  287.    Else
  288.       cmdRemoveAll.Enabled = False
  289.    End If
  290. End Sub
  291.  
  292.